/*
 * Copyright © 2020-2021 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springboot.mbp.config;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * {@link TableField @TableField}字段自动填充处理器。
 *
 * @author Denvie
 * @date 2021/7/1
 * @since 1.0.0
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("MybatisPlus insert auto fill...");
        this.strictInsertFill(metaObject, "gmtCreate", Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("MybatisPlus update auto fill...");
        this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date());
    }
}
